const http = require('../../../utils/http.js');
const app = getApp()
const utils = require('../../../utils/util.js')
Page({
  data: {
    phone:''
  },
  onLoad: function (options) {
    var _this = this
    var phone = wx.getStorageSync('member')
    _this.setData({
      phone:phone.mobile.replace(/^(\d{3})\d{4}(\d+)/,"$1****$2")
    })
  },
  onReady: function () {},
  onShow: function () {},
  onHide: function () {},
  onUnload: function () {},
  onPullDownRefresh: function () {},
  onReachBottom: function () {},
  onShareAppMessage: function () {},
  getPhoneNumber(e) {
    console.log(e)
    let encryptedData = e.detail.encryptedData;
    console.log(e)
    if (encryptedData) {
      var _this = this;
      wx.login({
        success: res => {
          _this.setData({
            code: res.code
          })
          var oauth_data = {};
          oauth_data.encryptedData = e.detail.encryptedData
          oauth_data.iv = e.detail.iv
          _this.bindMobile({
            type: '1',
            client_data: JSON.stringify(oauth_data),
            code: _this.data.code
          })
        }
      })
    }
  },
  //绑定手机号
  bindMobile(data) {
    let _this = this
    http.postRequest('v1/bindMobile', data,
      function (res) {
        console.log(res)
        var _student = wx.getStorageSync('member');
        _student.mobile = true;
        wx.setStorageSync('member', _student);
        wx.showToast({
          title: res.msg,
        })
      },
      function (res) {
        wx.showToast({
          title: res.msg,
          icon:'none'
        })
      })
  },
})